//
//  BaseViewController+RGCustom.m
//  RedGrass
//
//  Created by wukong on 2018/12/28.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "BaseViewController+RGCustom.h"

#define DEFAULTIMAGE [UIImage imageNamed:@"返回"]
#define DEFAULTWHITEIMAGE [UIImage imageNamed:@"ic_top_back_white"]



@implementation BaseViewController (RGCustom)

-(void)showBackButtonWithTarget:(id)target selector:(SEL)selector {
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setImage:[DEFAULTIMAGE imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0,kNavigationBtnSpaceHorizontal,40,40);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -8, 0, 8)];
    self.customNavBar.leftButton = leftBtn;
}

-(void)showBackButtonWithImage:(NSString *)image target:(id)target selector:(SEL)selector {
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setImage:[[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0,kNavigationBtnSpaceHorizontal,20,20);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -4, 0, 8)];
    self.customNavBar.leftButton = leftBtn;
}

-(void)showleftButtonTitle:(NSString *)title WithTarget:(id)target selector:(SEL)selector {
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:title forState:UIControlStateNormal & UIControlStateHighlighted];
    [leftBtn setTitleColor:UICOLOR_WITH_RGBINT(0x666666) forState:UIControlStateNormal & UIControlStateHighlighted];
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -4, 0, 4)];
    [leftBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0,kNavigationBtnSpaceHorizontal,50,20);
    self.customNavBar.leftButton = leftBtn;
}

-(void)showBackButton{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setImage:[DEFAULTIMAGE imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backTo) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0,kNavigationBtnSpaceHorizontal,40,40);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -8, 0, 8)];
   self.customNavBar.leftButton = leftBtn;

}



-(void)showWhiteBackButton{
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setImage:[DEFAULTWHITEIMAGE imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backTo) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0,kNavigationBtnSpaceHorizontal,40,40);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -8, 0, 8)];
    self.customNavBar.leftButton = leftBtn;
}

-(void)showRightButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector {
    
    UIButton * right = [UIButton buttonWithType:UIButtonTypeSystem];
    right.frame = CGRectMake(0, kNavigationBtnSpaceHorizontal, 80, kNavigationBtnHeight);
    right.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight ;//设置文字位置，现设为居右
    [right setTitle:title forState:UIControlStateNormal];
    [right setTintColor:[UIColor whiteColor]];
    [right setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [right.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
//    [right setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, -8)];
    [right addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    self.customNavBar.rightButtons = @[right];
}

-(void)showRightButtonWithTitle:(NSString *)title imageName:(NSString *)imageName target:(id)target selector:(SEL)selector{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [rightBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTintColor:[UIColor whiteColor]];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightBtn setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [rightBtn setTitle:title forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(0,
                                kNavigationBtnSpaceHorizontal,
                                60,
                                kNavigationBtnHeight);
    [rightBtn setTitleEdgeInsets:UIEdgeInsetsMake(3, -48, 0, 0)];
    [rightBtn setImageEdgeInsets:UIEdgeInsetsMake(4, 38, 3, 5)];
    self.customNavBar.rightButtons = @[rightBtn];
}




-(void)backTo {
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
